<?php // -*- mode:php; -*-

// This file is part of japmmfd.
//
// japmmfd is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// japmmfd distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with japmmfd.  If not, see <http://www.gnu.org/licenses/>.

/**
 * @file japmmfd.install
 *
 * The install hooks for the japmmfd module.
 *
 * @author peter.vizi@gmail.com
 */

/**
 * Implementation of hook_install.
 */
function japmmfd_install() {
    drupal_install_schema('japmmfd');
} // end function japmmfd_install

/**
 * Implementation of hook_uninstall.
 */
function japmmfd_uninstall() {
    drupal_uninstall_schema('japmmfd');
} // end function japmmfd_uninstall

/**
 * Implementation of hook_schema.
 */
function japmmfd_schema() {
    $schema['japmmfd_messages'] = 
	array('description' => 'The number, the sending time, the sender id, the receiver id and the private messages are stored in this table',
	      'fields' => array('mid' => array('description' => 'Message id.',
					       'type' => 'serial',
					       'size' => 'big',
					       'unsigned' => TRUE,
					       'not null' => TRUE),
				
				'time' => array('description' => 'The time when the message was generated',
						'type' => 'int',
						'unsigned' => TRUE,
						'not null' => TRUE),
				
				'sid' => array('description' => 'The Drupal id of the sender',
					       'type' => 'int',
					       'unsigned' => TRUE,
					       'default' => 0),
				
				'rid' => array('description' => 'The Drupal id of the recipient',
					       'type' => 'int',
					       'unsigned' => TRUE,
					       'default' => 0),
				
				'subject' => array('description' => 'The subject of the message',
						   'type' => 'varchar',
						   'length' => 30,
						   'not null' => TRUE),
				
				'message' => array('description' => 'The actual message',
						   'type' => 'text',
						   'size' => 'normal',
						   'not null' => TRUE,
						   'default' => ''),
				
				'refid' => array('description' => 'This is a reply to this message',
						 'type' => 'int',
						 'size' => 'big',
						 'unsigned' => TRUE,
						 'default' => 0),
				
				'unseen' => array('description' => 'Indicate if this message was displayed.',
						  'type' => 'int',
						  'size' => 'tiny',
						  'unsigned' => TRUE,
						  'default' => 0),

				's_copy' => array('description' => 'This is 1 if the sender needs a copy from this message.',
						  'type' => 'int',
						  'size' => 'tiny',
						  'unsigned' => TRUE,
						  'default' => 1),

				'r_copy' => array('description' => 'This is 1 if the recipient needs a copy from this message.',
						  'type' => 'int',
						  'size' => 'tiny',
						  'unsigned' => TRUE,
						  'default' => 1)
				),
	      'indexes' => array('sid_idx' => array('sid', 's_copy'),
				 'rid_idx' => array('rid', 'r_copy'),
				 'del_idx' => array('s_copy', 'r_copy'),
				 'unseen_idx' => array('rid', 'unseen')),
	      'primary key' => array('mid'));
    return $schema;
} // end function japmmfd_schema
